package com.crland.service.impl;

import com.crland.entity.MemberInfo;
import com.crland.mapper.MemberInfoMapper;
import com.crland.service.MemberInfoService;
import com.crland.utils.DataSourceContextHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.HashSet;
import java.util.Set;

public class MemberInfoServiceImpl implements MemberInfoService{
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public int deleteByPrimaryKey(String id) {
        return 0;
    }

    @Override
    public int insert(MemberInfo record) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        DataSourceContextHolder.setDbType("msDataSource");
        MemberInfoMapper memberInfoMapper = ctx.getBean(MemberInfoMapper.class);
        memberInfoMapper.insert(record);
        return 0;
    }

    @Override
    public int insertSelective(MemberInfo record) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        DataSourceContextHolder.setDbType("msDataSource");
        MemberInfoMapper memberInfoMapper = ctx.getBean(MemberInfoMapper.class);
        memberInfoMapper.insertSelective(record);
        return 0;
    }

    @Override
    public MemberInfo selectByPrimaryKey(String id) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        DataSourceContextHolder.setDbType("msDataSource");
        MemberInfoMapper memberInfoMapper = ctx.getBean(MemberInfoMapper.class);
        MemberInfo memberInfo;
        memberInfo = memberInfoMapper.selectByPrimaryKey(id);
        return memberInfo;
    }

    @Override
    public int updateByPrimaryKeySelective(MemberInfo record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(MemberInfo record) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        DataSourceContextHolder.setDbType("msDataSource");
        MemberInfoMapper memberInfoMapper = ctx.getBean(MemberInfoMapper.class);
        memberInfoMapper.updateByPrimaryKey(record);
        return 0;
    }

    @Override
    public Set<String> allIdSet() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        DataSourceContextHolder.setDbType("msDataSource");
        MemberInfoMapper memberInfoMapper = ctx.getBean(MemberInfoMapper.class);
        Set<String> hashSet = new HashSet<>(memberInfoMapper.selectAllId());
        return hashSet;
    }

    @Override
    public Set<MemberInfo> getAllSet() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        DataSourceContextHolder.setDbType("msDataSource");
        MemberInfoMapper memberInfoMapper = ctx.getBean(MemberInfoMapper.class);
        Set<MemberInfo> memberInfoSet = new HashSet<>(memberInfoMapper.selectAll());
        return memberInfoSet;
    }

    @Override
    public int reset() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        DataSourceContextHolder.setDbType("msDataSource");
        MemberInfoMapper memberInfoMapper = ctx.getBean(MemberInfoMapper.class);
        memberInfoMapper.reset();
        return 0;
    }
}
